package cn.cttic.resource.controller;


import cn.cttic.common.core.domain.R;
import cn.cttic.common.core.utils.MapstructUtils;
import cn.cttic.common.core.utils.StringUtils;
import cn.cttic.common.core.validate.QueryGroup;
import cn.cttic.common.log.annotation.Log;
import cn.cttic.common.log.enums.BusinessType;
import cn.cttic.common.mybatis.core.page.PageQuery;
import cn.cttic.common.mybatis.core.page.TableDataInfo;
import cn.cttic.common.web.core.BaseController;
import cn.cttic.resource.api.domain.RemoteFile;
import cn.cttic.resource.domain.bo.SysOssBo;
import cn.cttic.resource.domain.vo.SysOssUploadVo;
import cn.cttic.resource.domain.vo.SysOssVo;
import cn.cttic.resource.service.ISysOssService;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 文件上传 控制层
 *
 * @author Times.Studio
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oss/dict")
public class SysOssDictController extends BaseController {

    private final ISysOssService iSysOssService;

    /**
     * 查询OSS对象存储列表
     */
    @GetMapping("/selectUrlByIds")
    public R<String> selectUrlByIds(@RequestParam(value = "ossIds") String ossIds) {
        String result = iSysOssService.selectUrlByIds(ossIds);
        if (StrUtil.isNotBlank(result)) {
            return R.ok("成功", result);
        } else {
            return R.fail("未找到OSS对象", null);
        }
    }

    /**
     * 查询OSS对象基于id串
     *
     * @param ossIds OSS对象ID串
     */
    @GetMapping("/selectByIds")
    public R<List<RemoteFile>> selectByIds(@RequestParam(value = "ossIds") String ossIds) {
        List<SysOssVo> list = iSysOssService.listByIds(StringUtils.splitTo(ossIds, Convert::toLong));
        if (CollUtil.isNotEmpty(list)) {
            return R.ok("成功", MapstructUtils.convert(list, RemoteFile.class));
        } else {
            return R.fail("未能找到OSS对象");
        }
    }

}
